package com.abc.icespringboot.util.annotationdemo;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * @author hp
 * @version 1.0
 * @description: ${description}
 * @date: 13:39 2018/9/30 0030
 */
public class FruitInfoUtil {
    public static void getFruitInfo(Class<?> clazz) {
        String strFruitName = "水果名称: ";
        String strFruitColor = "水果颜色: ";
        String strFruitProvicer = "供应商信息: ";
        String strFruitEatMethod = "水果吃法: ";

        Field[] fields = clazz.getDeclaredFields();
        for (Field field :
                fields) {
            if (field.isAnnotationPresent(FruitName.class)) {
                FruitName fruitName = (FruitName) field.getAnnotation(FruitName.class);
                strFruitName = strFruitName + fruitName.value();
                System.out.println(strFruitName);
            } else if (field.isAnnotationPresent(FruitColor.class)) {
                FruitColor fruitColor = (FruitColor) field.getAnnotation(FruitColor.class);
                strFruitColor = strFruitColor + fruitColor.fruitColor().toString();
                System.out.println(strFruitColor);
            } else if (field.isAnnotationPresent(FruitProvider.class)) {
                FruitProvider fruitProvider = (FruitProvider) field.getAnnotation(FruitProvider.class);
                strFruitProvicer = strFruitProvicer +
                        "供应商编号: " + fruitProvider.id() +
                        "供应商名称: " + fruitProvider.name() +
                        "供应商地址: " + fruitProvider.address();
                System.out.println(strFruitProvicer);
            }
        }

        Method[] methods = clazz.getDeclaredMethods();
        for (Method method :
                methods) {
            if (method.isAnnotationPresent(FruitEatMethod.class)) {
                FruitEatMethod fruitEatMethod = (FruitEatMethod) method.getAnnotation(FruitEatMethod.class);
                strFruitEatMethod = strFruitEatMethod + fruitEatMethod.eatMethod();
                System.out.println(strFruitEatMethod);
            }
        }

    }
}
